# -*- coding:utf-8 -*-
import redis


class RedisHelper:

    def __init__(self):
        self.__conn = redis.Redis(host='127.0.0.1', port=56379, decode_responses=True)
        self.chan_sub = 'fm104.5'
        self.chan_pub = 'fm104.5'

    def public(self, msg):
        self.__conn.publish(self.chan_pub, msg)  # 开始发布消息

        return True

    def subscribe(self):
        pub = self.__conn.pubsub()  # 开始订阅
        pub.subscribe(self.chan_sub)  # 订阅频道
        pub.parse_response()  # 准备接收
        return pub